<template>
  <div @mouseenter="mouseIn" @mouseleave="mouseOut" :class="{ focus: isFocus }">
    <el-card style="max-width: 260px; padding: 3% !important">
      <el-image class="Image" :src="sPath" @click="handleClickPicture">
      </el-image>
      <div>
        <el-row :gutter="10" type="flex" justify="center">
          <el-col :span="6">
            <el-popover placement="right" width="300" trigger="hover">
              <el-descriptions title="资源详情" :column="2" border transition>
                <el-descriptions-item label="资源ID">{{
                  sId
                }}</el-descriptions-item>
                <el-descriptions-item label="更新时间">{{
                  formartDateString
                }}</el-descriptions-item>
                <el-descriptions-item label="路径">{{
                  sPath
                }}</el-descriptions-item>
              </el-descriptions>
              <p slot="reference" style="text-align: center; margin: 0%">
                <i class="el-icon-info pictureCardInfo"></i>
              </p>
            </el-popover>
          </el-col>
          <!-- <el-col :span="16">
              <h5 class="picname">{{ sName }}</h5>
            </el-col> -->
          <el-col :span="6">
            <el-popover placement="right" trigger="hover" content="设置为新闻大图" width="150px">
              <p style="text-align: center; margin: 0%" slot="reference">
                <i
                  class="el-icon-edit pictureCardRemove"
                  style="text-align: right"
                  @click="handlePictureCardAddToTitlePicClick"
                ></i>
              </p>
            </el-popover>
          </el-col>
          <el-col :span="6">
            <el-popover placement="right" trigger="hover" content="添加到关联图片" width="150px">
              <p style="text-align: center; margin: 0%" slot="reference" >
                <i
                  class="el-icon-circle-plus pictureCardRemove"
                  style="text-align: right"
                  @click="handlePictureCardAddToRelationPicClick"
                ></i>
              </p>
            </el-popover>
          </el-col>
        </el-row>
      </div>
    </el-card>
  </div>
</template>
    <script>
import { fileSiteUrl } from "@/api/constTools";
// import { log } from "console";
export default {
  name: "PictureCardForArticleAdd",
  data() {
    return {
      // 此处所有的数据应该是从上级组件中传回来的
      sId: 0,
      sPath: "",
      sUpdateTime: "",
      sName: "",

      srcList: [],
      isFocus: false,
      BaseApiUrl: fileSiteUrl,
    };
  },
  computed: {
    formartDateString() {
      var index = this.sUpdateTime.lastIndexOf("+");
      return this.sUpdateTime.slice(0, index);
    },
  },
  methods: {
    initSrcData() {
      // let that=this;

      this.sId = this.data.sId;
      this.sPath = this.BaseApiUrl + this.data.sPath;
      this.sUpdateTime = this.data.sUpdateTime;
      this.sName = this.data.sName;

      // this.srcList = [];
      // this.srcList.push(this.sPath);
    },
    mouseIn() {
      //   console.log("mouse in");
      // 鼠标移入时，改变当前项样式
      // console.log(this.$refs["imageCard"]);
      this.isFocus = true;
    },
    mouseOut() {
      //   console.log("mouse out");
      this.isFocus = false;
    },
    handlepictureCardRemoveClick() {
      // this.$message.info("点击了");
      // console.log(this.BaseApiUrl);
      // console.log(BaseApiUrl);
      this.$emit("deleteSingleSource", this.sId);
    },
    handlePictureCardAddToTitlePicClick() {
      this.$emit("pictureCardAddToTitlePic", this.sId);
    },
    handlePictureCardAddToRelationPicClick(){
        // 此处要传回一个source对象
        let Object={
            "sId":this.sId,
            "sName":this.sName,
            "sPath":this.sPath
        }
      this.$emit("pictureCardAddToRelationPic", Object);
    },
    handleClickPicture() {
      // 将子组件中的信息传回父组件
      // console.log("111");
      this.$emit("handlePreview", this.sPath);
    },
  },
  props: ["data"],
  mounted() {
    this.initSrcData();
    // console.log(this.BaseApiUrl);
  },
};
</script>
  <style>
.el-card__body {
  padding: 0% !important;
}
</style>
  <style scoped>
.focus {
  transform: scale(1.1);
}
.picname {
  margin: 0% !important;
  text-align: center;
  white-space: nowrap;
  /* 2.溢出的部分隐藏起来 */
  overflow: hidden;
  /* 3.文字溢出的时候用省略号来显示 */
  text-overflow: ellipsis;
}
.pictureCardInfo:hover,
.pictureCardRemove:hover {
  color: red;
}
.Image {
  max-height: 120px !important;
  min-height: 120px !important;
  overflow: hidden;
}
.Image  img{
  /* width: 92% !important; */
  /* min-width: 185px; */
  min-height: 120px !important;
}
</style>